<?php

namespace App\Requests\Permission;

use Illuminate\Foundation\Http\FormRequest;

class AdminRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $rules = [
            'username' => 'required',
            'account' => 'required',
            'status' => 'required',
        ];

        if($this->method() == 'POST'){
            // 如果是更新操作，可以添加额外字段
            $rules['password'] = 'sometimes|required'; // 可选字段
        }
        return $rules;
    }

    /**
     * 获取验证错误消息。
     *
     * @return array
     */
    public function messages(): array
    {
        return [
            'username.required'     => '名称是必填项。',
            'account.required'  => '账号是必填项。',
            'password.required' => '密码是必填项。',
            'status.required'   => '状态是必填项。',
        ];
    }
}
